<Tree @ref="_tree"
      Checkable
      TItem="string"
      @bind-ExpandedKeys="expandedKeys"
      @bind-CheckedKeys="checkedKeys"
      @bind-SelectedKeys="selectedKeys"
      OnExpand="OnExpand"
      OnSelect="OnSelect"
      OnCheck="OnCheck"
      AutoExpandParent="autoExpandParent">
    <Nodes>
        <TreeNode Title="0-0" Key="0-0" TItem="string">
            <Nodes>
                <TreeNode Title="0-0-0" Key="0-0-0" TItem="string">
                    <Nodes>
                        <TreeNode Title="0-0-0-0" Key="0-0-0-0" TItem="string"></TreeNode>
                        <TreeNode Title="0-0-0-1" Key="0-0-0-1" TItem="string"></TreeNode>
                        <TreeNode Title="0-0-0-2" Key="0-0-0-2" TItem="string"></TreeNode>
                    </Nodes>
                </TreeNode>
                <TreeNode Title="0-0-1" Key="0-0-1" TItem="string">
                    <Nodes>
                        <TreeNode Title="0-0-1-0" Key="0-0-1-0" TItem="string"></TreeNode>
                        <TreeNode Title="0-0-1-1" Key="0-0-1-1" TItem="string"></TreeNode>
                        <TreeNode Title="0-0-1-2" Key="0-0-1-2" TItem="string"></TreeNode>
                    </Nodes>
                </TreeNode>
                <TreeNode Title="0-0-2" Key="0-0-2" TItem="string"></TreeNode>
            </Nodes>
        </TreeNode>
        <TreeNode Title="0-1" Key="0-1" TItem="string">
            <Nodes>
                <TreeNode Title="0-1-0-0" Key="0-1-0-0" TItem="string"></TreeNode>
                <TreeNode Title="0-1-0-1" Key="0-1-0-1" DisableCheckbox TItem="string"></TreeNode>
                <TreeNode Title="0-1-0-2" Key="0-1-0-2" Disabled TItem="string"></TreeNode>
            </Nodes>
        </TreeNode>
        <TreeNode Title="0-2" Key="0-2" TItem="string"></TreeNode>
    </Nodes>
</Tree>

<br />
@*<Button OnClick="PrintCheckedNodesTitle">Print Checked Nodes Title</Button>*@

<Button OnClick="PrintCheckedNodesKey">Print Checked Nodes Key</Button>

<Button OnClick="DecheckedAll">Dechecked All</Button>
<br />
<br />

@*<Button OnClick="PrintSelectedNodes">Print Selected Nodes</Button>*@

<Button OnClick="DeselectAll">Deselect All</Button>
<br />

<Button OnClick="ExpandAll">Expand All Nodes</Button>

<Button OnClick="CollapseAll">Collapse All Nodes</Button>

@if (string.IsNullOrWhiteSpace(printType) == false)
{
    <div>@printType</div>
    <ul>
        @foreach (var item in printTexts)
        {
            <li>@item</li>
        }
    </ul>
}
@code {

    string printType;

    string[] printTexts;

    Tree<string> _tree;

    string[] expandedKeys;
    string[] checkedKeys;
    string[] selectedKeys;

    bool autoExpandParent;

    //private void PrintCheckedNodesTitle()
    //{
    //    printType = "CheckedNodesTitle";
    //    printTexts = tree.CheckedTitles;
    //}

    private void PrintCheckedNodesKey()
    {
        printType = "CheckedNodesKey";
        printTexts = _tree.CheckedKeys;
    }

    private void DecheckedAll()
    {
        _tree.DecheckedAll();
    }

    //private void PrintSelectedNodes()
    //{
    //    printType = "SelectedNodes";
    //    printTexts = tree.SelectedTitles;
    //}

    private void DeselectAll()
    {
        _tree.DeselectAll();
    }

    private void ExpandAll()
    {
        _tree.ExpandAll();
    }

    private void CollapseAll()
    {
        _tree.CollapseAll();
    }

    private void OnCheck(TreeEventArgs<string> e)
    {
        Console.WriteLine("OnCheck:" + e.Node.Key);
    }

    private void OnSelect(TreeEventArgs<string> e)
    {
        Console.WriteLine("OnSelect:" + e.Node.Key);
    }

    private void OnExpand((string[] ExpandedKeys, TreeNode<string> Node, bool Expanded) e)
    {
        Console.WriteLine("OnExpand:" + JsonSerializer.Serialize(e.ExpandedKeys));
    }
}